package com.wang.back.controller;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.common.pojo.BasePojoEnum;
import com.wang.common.pojo.BaseQuery;
import com.wang.common.util.ConstatFinalUtil;
import com.wang.common.web.controller.BaseController;
import com.wang.exam.pojo.AtExamDesc;
import com.wang.exam.pojo.AtExamDescEnum;
import com.wang.exam.pojo.AtExamDescQuery;
import com.wang.exam.pojo.AtExamIntvig;
import com.wang.exam.pojo.AtExamIntvigQuery;
import com.wang.exam.pojo.AtExamStat;
import com.wang.exam.pojo.AtExamStatQuery;
import com.wang.exam.pojo.AtNotice;
import com.wang.exam.pojo.AtNoticeQuery;
import com.wang.exam.service.AtExamDescService;
import com.wang.exam.service.AtExamIntvigService;
import com.wang.exam.service.AtExamStatService;
import com.wang.exam.service.AtNoticeService;
import com.wang.users.pojo.AtRbacAdmins;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 考试相关的Controller
 * @author ZjxMi
 */
@Controller
@RequestMapping("/back/exam")
@Log4j2
public class ExamBackController extends BaseController {
    @Autowired
    private AtExamDescService examDescService;
    @Autowired
    private AtExamIntvigService examIntvigService;
    @Autowired
    private AtExamStatService examStatService;
    @Autowired
    private AtNoticeService noticeService;

    /**
     * 考试概要查询多条
     * @return
     */
    @RequestMapping("/examDescList")
    public String examDescList(AtExamDescQuery paramQuery, Model model){
        log.info("==考试概要列表==");
        /* 分页对象 */
        IPage<AtExamDesc> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtExamDesc> dataList = this.examDescService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtExamDesc());
        /* 查询数据 */
        return "/back/exam/examDescList";
    }

    /**
     * 考试概要打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/examDescUpdate")
    public String examDescUpdate(AtExamDescQuery paramQuery, Model model){
        log.info("==考试概要更新==");
        /* 根据id查询 */
        AtExamDesc one = this.examDescService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "/back/exam/examDescUpdate";
        }
        /* 查询数据 */
        return "/back/exam/examDescInfo";
    }

    /**
     * 考试概要更新提交操作
     * <pre>
     * 考试概要表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/examDescUpdateSubmit")
    @ResponseBody
    public String examDescUpdateSubmit(HttpServletRequest request, AtExamDescQuery paramQuery, Model model){
        log.info("==考试概要更新提交==");
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        AtExamDesc entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        if (AtExamDescEnum.STATUSNEW_PASS.getCode().equalsIgnoreCase(entity.getStatus())) {
            /* 审核通过 */
            entity.setAuditId(adminsSess.getId());
            entity.setAuditTime(new Date());
        }
        boolean dbFlag = this.examDescService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 考试概要打开添加页面
     * @return
     */
    @RequestMapping("/examDescBatch")
    @ResponseBody
    public String examDescBatch(AtExamDescQuery paramQuery, Model model){
        log.info("==考试概要批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtExamDescQuery paramQueryTemp = new AtExamDescQuery();
                        AtExamDesc entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtExamDesc dataDbResult = this.examDescService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.examDescService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtExamDescQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.examDescService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtExamDescQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.examDescService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.examDescService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 监考记录查询多条
     * @return
     */
    @RequestMapping("/intvigList")
    public String intvigList(AtExamIntvigQuery paramQuery, Model model){
        log.info("==监考记录列表==");
        /* 分页对象 */
        IPage<AtExamIntvig> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtExamIntvig> dataList = this.examIntvigService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtExamIntvig());
        /* 查询数据 */
        return "/back/exam/intvigList";
    }

    /**
     * 监考记录打开添加页面
     * @return
     */
    @RequestMapping("/intvigInsert")
    public String intvigInsert(AtExamIntvigQuery paramQuery, Model model){
        log.info("==监考记录添加==");
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtExamIntvig());
        /* 查询数据 */
        return "/back/exam/intvigInsert";
    }

    /**
     * 监考记录添加提交操作
     * @return
     */
    @RequestMapping("/intvigInsertSubmit")
    @ResponseBody
    public String intvigInsertSubmit(AtExamIntvigQuery paramQuery, Model model){
        log.info("==监考记录添加提交==");
        boolean dbFlag = this.examIntvigService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 监考记录打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/intvigUpdate")
    public String intvigUpdate(AtExamIntvigQuery paramQuery, Model model){
        log.info("==监考记录更新==");
        /* 根据id查询 */
        AtExamIntvig one = this.examIntvigService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "/back/exam/intvigUpdate";
        }
        /* 查询数据 */
        return "/back/exam/intvigInfo";
    }

    /**
     * 监考记录更新提交操作
     * <pre>
     * 监考记录表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/intvigUpdateSubmit")
    @ResponseBody
    public String intvigUpdateSubmit(HttpServletRequest request,AtExamIntvigQuery paramQuery, Model model){
        log.info("==监考记录更新提交==");
        AtExamIntvig entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        AtRbacAdmins adminsSess = (AtRbacAdmins) this.findObjFromSession(request, BasePojoEnum.SESS_ADMINS);
        if (AtExamDescEnum.STATUSNEW_PASS.getCode().equalsIgnoreCase(entity.getStatus())) {
            /* 审核通过 */
            entity.setAuditId(adminsSess.getId());
            entity.setAuditTime(new Date());
        }
        boolean dbFlag = this.examIntvigService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 监考记录打开添加页面
     * @return
     */
    @RequestMapping("/intvigBatch")
    @ResponseBody
    public String intvigBatch(AtExamIntvigQuery paramQuery, Model model){
        log.info("==监考记录批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtExamIntvigQuery paramQueryTemp = new AtExamIntvigQuery();
                        AtExamIntvig entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtExamIntvig dataDbResult = this.examIntvigService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.examIntvigService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtExamIntvigQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.examIntvigService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtExamIntvigQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.examIntvigService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.examIntvigService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 统计查询多条
     * @return
     */
    @RequestMapping("/statList")
    public String statList(AtExamStatQuery paramQuery, Model model){
        log.info("==统计列表==");
        /* 分页对象 */
        IPage<AtExamStat> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtExamStat> dataList = this.examStatService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtExamStat());
        /* 查询数据 */
        return "/back/exam/statList";
    }

    /**
     * 统计打开添加页面
     * @return
     */
    @RequestMapping("/statInsert")
    public String statInsert(AtExamStatQuery paramQuery, Model model){
        log.info("==统计添加==");
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtExamStat());
        /* 查询数据 */
        return "/back/exam/statInsert";
    }

    /**
     * 统计添加提交操作
     * @return
     */
    @RequestMapping("/statInsertSubmit")
    @ResponseBody
    public String statInsertSubmit(AtExamStatQuery paramQuery, Model model){
        log.info("==统计添加提交==");
        boolean dbFlag = this.examStatService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 统计打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/statUpdate")
    public String statUpdate(AtExamStatQuery paramQuery, Model model){
        log.info("==统计更新==");
        /* 根据id查询 */
        AtExamStat one = this.examStatService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "/back/exam/statUpdate";
        }
        /* 查询数据 */
        return "/back/exam/statInfo";
    }

    /**
     * 统计更新提交操作
     * <pre>
     * 统计表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/statUpdateSubmit")
    @ResponseBody
    public String statUpdateSubmit(AtExamStatQuery paramQuery, Model model){
        log.info("==统计更新提交==");
        AtExamStat entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.examStatService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 批量统计老师的监考信息
     * @return  返回页面所需要的json字符串
     */
    @RequestMapping("/statProccedSaveBatch")
    @ResponseBody
    public String statProccedSaveBatch() {
        log.info("==批量统计老师的监考信息==");
        boolean dbFlag = this.examStatService.proccedSaveBatch();
        String messInfo = "";
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);
        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(true, paramsMap);
        log.info("==提示信息:{}==数据库结果:{}", resultJson, dbFlag);
        return resultJson.toJSONString();
    }

    /**
     * 统计打开添加页面
     * @return
     */
    @RequestMapping("/statBatch")
    @ResponseBody
    public String statBatch(AtExamStatQuery paramQuery, Model model){
        log.info("==统计批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtExamStatQuery paramQueryTemp = new AtExamStatQuery();
                        AtExamStat entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtExamStat dataDbResult = this.examStatService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.examStatService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtExamStatQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.examStatService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtExamStatQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.examStatService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.examStatService.updateById(dataDbResult);
                            } else if ("intvigBatch".equalsIgnoreCase(operType)) {
                                /* 批量添加老师 */
                                String examExtendId = paramQuery.getExamExtendId();
                                AtExamIntvig intvigBatch = new AtExamIntvig();
                                intvigBatch.setUsersId(dataDbResult.getUsersId());
                                intvigBatch.setExamId(examExtendId);
                                dbFlag = this.examIntvigService.save(intvigBatch);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }

    /**
     * 公告查询多条
     * @return
     */
    @RequestMapping("/noticeList")
    public String noticeList(AtNoticeQuery paramQuery, Model model){
        log.info("==公告列表==");
        /* 分页对象 */
        IPage<AtNotice> paramPage = null;
        try {
            paramPage = new Page<>(paramQuery.getCurrent(), paramQuery.getSize());
        } catch (Exception e) {
            paramPage = new Page<>(1, 20);
        }
        /* 时间处理 */
        if (StringUtils.isNotEmpty(paramQuery.getStDate())) {
            paramQuery.setPubTimeSt(this.dateUtil.strToDateTime(paramQuery.getStDate()));
        }
        if (StringUtils.isNotEmpty(paramQuery.getEdDate())) {
            paramQuery.setPubTimeEd(this.dateUtil.strToDateTime(paramQuery.getEdDate()));
        }
        paramQuery.addLike();
        /* 查询对象 */
        List<AtNotice> dataList = this.noticeService.findList(paramPage, paramQuery);
        paramQuery.removeLike();
        /* 列表数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_DATALIST, dataList);
        /* 分页数据 */
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PAGEINFOUTIL, paramPage);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_PARAMQUERY, paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ENUMSONE, new AtNotice());
        /* 查询数据 */
        return "/back/exam/noticeList";
    }

    /**
     * 公告打开添加页面
     * @return
     */
    @RequestMapping("/noticeInsert")
    public String noticeInsert(AtNoticeQuery paramQuery, Model model){
        log.info("==公告添加==");
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, new AtNotice());
        /* 查询数据 */
        return "/back/exam/noticeInsert";
    }

    /**
     * 公告添加提交操作
     * @return
     */
    @RequestMapping("/noticeInsertSubmit")
    @ResponseBody
    public String noticeInsertSubmit(AtNoticeQuery paramQuery, Model model){
        log.info("==公告添加提交==");
        boolean dbFlag = this.noticeService.save(paramQuery.getEntity());
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 公告打开更新页面
     * 更新和详情是同一个页面;
     * @return
     */
    @RequestMapping("/noticeUpdate")
    public String noticeUpdate(AtNoticeQuery paramQuery, Model model){
        log.info("==公告更新==");
        /* 根据id查询 */
        AtNotice one = this.noticeService.findOne(paramQuery);
        model.addAttribute(ConstatFinalUtil.FINAL_CODE_ONE, one);

        if (BaseQuery.FINAL_OPER_UPDATE.equalsIgnoreCase(paramQuery.getOperType())) {
            /* 查询数据 */
            return "/back/exam/noticeUpdate";
        }
        /* 查询数据 */
        return "/back/exam/noticeInfo";
    }

    /**
     * 公告更新提交操作
     * <pre>
     * 公告表有10个字段,用户填写的只有5个字段;
     * 更新的时候只更新5个字段;剩下的5个字段不用更新
     * 千万不要把页面中传的参数SpringMVC会自动创建对象,这个对象不要直接更新数据库,很危险;
     * </pre>
     * @return
     */
    @RequestMapping("/noticeUpdateSubmit")
    @ResponseBody
    public String noticeUpdateSubmit(AtNoticeQuery paramQuery, Model model, HttpServletRequest request){
        log.info("==公告更新提交==");
        AtNotice entity = paramQuery.getEntity();
        if (StringUtils.isNotEmpty(paramQuery.getPubTime())) {
            entity.setPubTime(this.dateUtil.strToDateTime(paramQuery.getPubTime()));
        }
        boolean dbFlag = this.noticeService.updateById(entity);
        JSONObject resultJson = this.proccedResponseJson(dbFlag);
        /* 返回json给客户端 */
        return resultJson.toJSONString();
    }

    /**
     * 公告打开添加页面
     * @return
     */
    @RequestMapping("/noticeBatch")
    @ResponseBody
    public String noticeBatch(AtNoticeQuery paramQuery, Model model){
        log.info("==公告批量提交==");
        String operType = paramQuery.getOperType();
        String[] ids = paramQuery.getIds();
        String info = ConstatFinalUtil.FINAL_OPER_SUCCESS;
        int totalCount = 0;
        int succedCount = 0;
        int failedCount = 0;
        if (StringUtils.isNotEmpty(operType)) {
            if (Objects.nonNull(ids) && ids.length > 0) {
                totalCount = ids.length;
                for (String idTemp : ids) {
                    try {
                        AtNoticeQuery paramQueryTemp = new AtNoticeQuery();
                        AtNotice entity = paramQueryTemp.getEntity();
                        entity.setId(idTemp);
                        /* 根据id查询每一个 记录对象 */
                        AtNotice dataDbResult = this.noticeService.findOne(paramQueryTemp);
                        if (dataDbResult != null) {
                            boolean dbFlag = false;
                            if (BasePojoEnum.OPERTYPE_DELETE.getCode().equalsIgnoreCase(operType)) {
                                /* 删除 */
                                dbFlag = this.noticeService.removeById(idTemp);
                            } else if (BasePojoEnum.OPERTYPE_RESTORE.getCode().equalsIgnoreCase(operType)) {
                                /* 还原,为什么这里面要传这么多参数,一切的一切就是为了在xml中拼装sql语句 */
                                paramQueryTemp = new AtNoticeQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setDelFlag(BasePojoEnum.DELFLAG_NO.getCode());
                                entity.setId(idTemp);
                                paramQueryTemp.setOperType(BasePojoEnum.OPERTYPE_RESTORE.getCode());
                                dbFlag = this.noticeService.updateBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_EMPTY.getCode().equalsIgnoreCase(operType)) {
                                /* 清空 */
                                paramQueryTemp = new AtNoticeQuery();
                                entity = paramQueryTemp.getEntity();
                                entity.setId(idTemp);
                                dbFlag = this.noticeService.deleteBatch(paramQueryTemp) > 0 ;
                            } else if (BasePojoEnum.OPERTYPE_UPDATESTATUS.getCode().equalsIgnoreCase(operType)) {
                                /* 批量修改状态 */
                                dataDbResult.setStatus(paramQuery.getEntity().getStatus());
                                dbFlag = this.noticeService.updateById(dataDbResult);
                            }
                            if (dbFlag) {
                                succedCount ++;
                            } else {
                                failedCount ++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("批量操作失败了,id:{}", idTemp, e);
                        failedCount ++;
                    }
                }
            } else {
                /* 未选择类型,ids */
                info = "ids为空";
            }
        } else {
            /* 操作类型未选择 */
            info = "操作类型未选择";
        }

        String messInfo = "批量操作日志:提示信息:${info}, 总条数:${totalCount},成功条数:${succedCount},失败条数:${failedCount}";
        Map<String,String> paramsMap = new HashMap<>(1);
        paramsMap.put("info", info);
        paramsMap.put("totalCount", String.valueOf(totalCount));
        paramsMap.put("succedCount", String.valueOf(succedCount));
        paramsMap.put("failedCount", String.valueOf(failedCount));
        messInfo = this.regexUtil.replaceOperator(messInfo, paramsMap);

        paramsMap = new HashMap<>(1);
        paramsMap.put(ConstatFinalUtil.FINAL_CONFIG_INFO_SUCCESS_PARAM1, messInfo);
        /* 查询数据 */
        JSONObject resultJson = this.proccedResponseJson(ConstatFinalUtil.FINAL_OPER_SUCCESS.equalsIgnoreCase(info), paramsMap);
        log.info("==结果:{}==", resultJson);
        return resultJson.toJSONString();
    }
}